<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\Common;

class Rsa2Sign
{
    private $PRIVATE_KEY = "private_key";
    private $PUBLIC_KEY = "public_key";
    public function __construct($keys)
    {
        $this->PRIVATE_KEY = $keys["private_key"];
        $this->PUBLIC_KEY = $keys["public_key"];
    }
    private function getPrivateKey()
    {
        return openssl_pkey_get_private($this->PRIVATE_KEY);
    }
    private function getPublicKey()
    {
        return openssl_pkey_get_public($this->PUBLIC_KEY);
    }
    public function createSign($data = "")
    {
        if(!is_string($data)) {
            return NULL;
        }
        return openssl_sign($data, $sign, $this->getPrivateKey(), OPENSSL_ALGO_SHA256) ? base64_encode(base64_encode($sign)) : NULL;
    }
    public function verifySign($data = "", $sign = "")
    {
        if(!is_string($sign) || !is_string($sign)) {
            return false;
        }
        $sign = base64_decode($sign);
        return (bool) openssl_verify($data, base64_decode($sign), $this->getPublicKey(), OPENSSL_ALGO_SHA256);
    }
    public function encrypt($data)
    {
        $key = openssl_pkey_get_public($this->PUBLIC_KEY);
        if(!$key) {
            return false;
        }
        $return_en = openssl_public_encrypt($data, $crypted, $key);
        if(!$return_en) {
            return false;
        }
        $eb64_cry = base64_encode($crypted);
        return $eb64_cry;
    }
    public function decrypt($data)
    {
        $private_key = openssl_pkey_get_private($this->PRIVATE_KEY);
        if(!$private_key) {
            return false;
        }
        $return_check = openssl_private_decrypt(base64_decode($data), $decrypted, $private_key);
        if(!$return_check) {
            return false;
        }
        return $decrypted;
    }
}

?>